查看原文
其他

csdid2:多时期DID的异质性稳健估计量

csdid2:多时期DID的异质性稳健估计量

来源:https://github.com/friosavila/csdid2


CSDID的新版本全是用Mata语句写的

这是一个新版本的csdid,现在完全集成到Mata。这样比以前运行速度更快!

下面可以看看它是如何工作的:

1、下载安装

首先需要下载安装如下四个文件

csdid2.ado 、csdid2_clean.ado 、csdid2_estat.ado、lcsdid.mlib

主页为:https://github.com/friosavila/csdid2

2、应用案例

首先下载该FRAUSE命令,然后导入数据

  • Fernando Rios-Avila, 2022. "FRAUSE: Stata module to access Wooldridge Stata datasets," Statistical Software Components S459127, Boston College Department of Economics, revised 01 Oct 2022.

FRAUSE可以使用stata格式数据集《"Introductory Econometrics: a Modern Approach》作者:伍尔德里奇。这应该包含本书在示例和练习中使用的所有数据集,

下载方法为:

ssc install frause

help frause

然后导入数据

. frause mpdta, clear
(Written by R.              )

查看数据结果为:



. ed

. desc

Contains data from https://friosavila.github.io/playingwithstata/data2/mpdta.dta
  obs:         2,500                          Written by R.              
 vars:             6                          5 Oct 2022 07:36
-----------------------------------------------------------------------------------------------------------------------------
              storage   display    value
variable name   type    format     label      variable label
-----------------------------------------------------------------------------------------------------------------------------
year            int     %9.0g                 year
countyreal      long    %9.0g                 countyreal
lpop            double  %9.0g                 lpop
lemp            double  %9.0g                 lemp
first_treat     int     %9.0g                 first.treat
treat           byte    %9.0g                 treat
-----------------------------------------------------------------------------------------------------------------------------
Sorted by: 

下面进行估计

这将生成所有内容,但不显示任何内容!除非你要求。

这可以使用agg(attgt) or agg(group)等选项来完成

. csdid2 lemp, ivar(countyreal) tvar(year) gvar(first)
Always Treated units have been excluded
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
............
* However after that is done, you can just use estat to produce outcomes you want

. estat event
------------------------------------------------------------------------------
             | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
     Pre_avg |   .0018283    .007657     0.24   0.811    -.0131791    .0168357
    Post_avg |  -.0772398    .019965    -3.87   0.000    -.1163705   -.0381092
         tm3 |   .0305067   .0150336     2.03   0.042     .0010414    .0599719
         tm2 |  -.0005631   .0132916    -0.04   0.966    -.0266142    .0254881
         tm1 |  -.0244587   .0142364    -1.72   0.086    -.0523616    .0034441
         tp0 |  -.0199318   .0118264    -1.69   0.092    -.0431111    .0032474
         tp1 |  -.0509574   .0168935    -3.02   0.003     -.084068   -.0178468
         tp2 |  -.1372587   .0364357    -3.77   0.000    -.2086713   -.0658461
         tp3 |  -.1008114   .0343592    -2.93   0.003    -.1681542   -.0334685
------------------------------------------------------------------------------
* This produces Asymptotic Standard errors by default. But you can also reqyest bootstrap (no saverif anymore)

. estat event, wboot
---------------------------------------------------------------------
            | Coefficient  Std. err.      t      [95% conf. interval]
------------+--------------------------------------------------------
    Pre_avg |   .0018283   .0076744     0.24    -.0172037    .0208603
   Post_avg |  -.0772398    .020526    -3.76    -.1281428   -.0263368
        tm3 |   .0305067   .0156614     1.95    -.0083324    .0693458
        tm2 |  -.0005631    .013331    -0.04    -.0336231    .0324969
        tm1 |  -.0244587   .0147201    -1.66    -.0609636    .0120462
        tp0 |  -.0199318   .0116118    -1.72    -.0487284    .0088648
        tp1 |  -.0509574   .0162214    -3.14    -.0911853   -.0107294
        tp2 |  -.1372587   .0367764    -3.73    -.2284616   -.0460559
        tp3 |  -.1008114   .0358325    -2.81    -.1896734   -.0119493
---------------------------------------------------------------------
WildBootstrap Standard errors
with 999 Repetitions

** But the fun doesnt end there. You can also plot!
. estat event, wboot plot
[Plot not included but you can check it out]

窗口、选择的组或年份呢?新命令在这方面更加通用。例如,我可以为一个较小的窗口产生事件估计,或仅为1个队列,或1年!或者混合搭配,或者使用年份组等等


. estat event , revent(-2/2)
------------------------------------------------------------------------------
             | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
     Pre_avg |  -.0125109   .0090595    -1.38   0.167    -.0302671    .0052453
    Post_avg |  -.0693826   .0172695    -4.02   0.000    -.1032302   -.0355351
         tm2 |  -.0005631   .0132916    -0.04   0.966    -.0266142    .0254881
         tm1 |  -.0244587   .0142364    -1.72   0.086    -.0523616    .0034441
         tp0 |  -.0199318   .0118264    -1.69   0.092    -.0431111    .0032474
         tp1 |  -.0509574   .0168935    -3.02   0.003     -.084068   -.0178468
         tp2 |  -.1372587   .0364357    -3.77   0.000    -.2086713   -.0658461
------------------------------------------------------------------------------

 estat event , rgroup(2006)
------------------------------------------------------------------------------
             | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
     Pre_avg |   .0018846    .015671     0.12   0.904      -.02883    .0325993
    Post_avg |  -.0229095   .0167033    -1.37   0.170    -.0556475    .0098284
         tm2 |   .0065201   .0233268     0.28   0.780    -.0391996    .0522398
         tm1 |  -.0027508   .0195586    -0.14   0.888    -.0410849    .0355833
         tp0 |  -.0045946   .0177552    -0.26   0.796    -.0393942    .0302049
         tp1 |  -.0412245   .0202292    -2.04   0.042    -.0808729    -.001576
------------------------------------------------------------------------------

estat event , rcalendar(2006)
------------------------------------------------------------------------------
             | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
     Pre_avg |  -.0310871   .0178775    -1.74   0.082    -.0661264    .0039522
    Post_avg |  -.0709267   .0216675    -3.27   0.001    -.1133943   -.0284591
         tm1 |  -.0310871   .0178775    -1.74   0.082    -.0661264    .0039522
         tp0 |  -.0045946   .0177552    -0.26   0.796    -.0393942    .0302049
         tp2 |  -.1372587   .0364357    -3.77   0.000    -.2086713   -.0658461
------------------------------------------------------------------------------


现在最大的不同(如果你注意到的话)是所有的IF信息都使用Mata保存在内存中。所以,如果你做其他事情,你可能想要清理创建的对象:

csdid2 , clear

或者,更好的方法是将对象保存在磁盘中,以便在需要时可以返回分析。

csdid2 save_ex1, save
clear all
csdid2 save_ex1, load


您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存